﻿<navigation:PageView x:Class="Corina.Cydee.Apphub.Views.Devices.TransferView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                     xmlns:localViewmodel="clr-namespace:Corina.Cydee.Apphub.Viewmodels"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:navigation="clr-namespace:Corina.Cydee.Apphub.Base"
                     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                     xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                     Title="数据模块"
                     d:DesignHeight="480"
                     d:DesignWidth="640"
                     mc:Ignorable="d">
    <navigation:PageView.DataContext>
        <localViewmodel:TransferViewmodel />
    </navigation:PageView.DataContext>
    <Grid x:Name="LayoutRoot">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Button Width="60"
                    HorizontalAlignment="Right"
                    Command="{Binding InsertCommand}"
                    Content="新增" />

            <toolkit:BusyIndicator Grid.Row="1"
                                   BusyContent="{StaticResource IDS_BUSYCONTENT_LOADING}"
                                   IsBusy="{Binding IsBusy}">
                <sdk:DataGrid Margin="0,12,0,0"
                              AutoGenerateColumns="False"
                              ColumnWidth="*"
                              HorizontalScrollBarVisibility="Disabled"
                              IsReadOnly="True"
                              ItemsSource="{Binding ItemsCollection}">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn Binding="{Binding Title}" Header="标题" />
                        <sdk:DataGridTextColumn Binding="{Binding Description}" Header="描述" />
                        <sdk:DataGridTemplateColumn Header="是否可用">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Button Style="{StaticResource CheckButtonStyle}" Visibility="{Binding IsAvailable, Converter={StaticResource BooleanToVisibilityConverter}}">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.ChangeCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </Button>
                                        <Button Style="{StaticResource CrossButtonStyle}" Visibility="{Binding IsAvailable, Converter={StaticResource BooleanToVisibilityInverseConverter}}">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.ChangeCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </Button>
                                    </Grid>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                        <sdk:DataGridTemplateColumn Header="操作">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel VerticalAlignment="Center" Orientation="Horizontal">

                                        <HyperlinkButton Content="编辑">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.UpdateCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                        <HyperlinkButton Margin="12,0" Content="删除">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                    </StackPanel>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>
            </toolkit:BusyIndicator>

            <Grid Grid.Row="2"
                  Margin="0,12"
                  Visibility="{Binding ShowUpdate,
                                       Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBlock VerticalAlignment="Center" Text="标题：" />
                <TextBox Grid.Column="1" Text="{Binding UpdateEntity.Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <TextBlock Grid.Column="2"
                           Margin="12,0,0,0"
                           VerticalAlignment="Center"
                           Text="描述：" />
                <TextBox Grid.Column="3" Text="{Binding UpdateEntity.Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <CheckBox Grid.Column="4"
                          Margin="12,0,0,0"
                          VerticalAlignment="Center"
                          Content="是否可用？"
                          IsChecked="{Binding UpdateEntity.IsAvailable,
                                              Mode=TwoWay}" />
                <StackPanel Grid.Column="5"
                            HorizontalAlignment="Right"
                            Orientation="Horizontal">
                    <Button Width="60"
                            Margin="12,0"
                            Command="{Binding SubmitCommand}"
                            Content="提交" />
                    <Button Width="60"
                            Command="{Binding CancelCommand}"
                            Content="取消" />
                </StackPanel>
            </Grid>
        </Grid>
    </Grid>
</navigation:PageView>
